<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Transaksi
 *
 * @author Hadi
 */
class transaksi_internal extends Admin_My_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->model('transaksi/model_transaksi_internal');
        $this->load->helper('transaksi_internal');
    }

    /**
     * QUOTATION
     */
    public function po_to_supplier($is_popup = 0) {
        $this->load->library("datagrid");

        $data = array();

        $this->log_event = "Membuka menu po to supplier";

        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-d");
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
        $data['srcPeriodMode'] = $this->input->get_post('srcPeriodMode') != "";

        $field_name = array("q.nomor_po", "q.subject", "c.nama_supplier");
        $field_title = array("Nomor PO", "Subjek", "To");
        $field_type = array("text", "text", "text");

        $filter_panel = new FilterPanel(base_url() . "transaksi/po_to_supplier", $field_name, $field_title, $field_type);
        if ($data['srcPeriodMode'] == 'include')
            $where = " WHERE date(q.tanggal_po) BETWEEN '" . $data['srcPeriodStart'] . "' AND '" . $data['srcPeriodEnd'] . "' ";
        else
            $where = " WHERE TRUE ";
        $filter = $filter_panel->getFilterString();
        $where .= $filter ? " AND $filter " : "";

        $offset = $this->input->get("per_page") ? $this->input->get("per_page") : 0;
        $length = 30;
        $result = $this->model_transaksi_internal->getPOSuppData($where, $offset, $length);
        $rowCount = $result->num_rows();

        if (!$is_popup) {
            $this->datagrid->setActionColumnsWidth(50);
            $this->datagrid->addMenu(GreyBox::createLink(base_url() . "index.php/transaksi_internal/po_to_supplier_add/", "", "Tambah Data", "add", "onclick", 1024, 600));
            $this->datagrid->addMenu("<a href=\"" . base_url() . "index.php/transaksi_internal/po_to_supplier_export/?" . $this->input->server("QUERY_STRING") . "\" class=\"report\" title=\"Export Data PO\">&nbsp;</a>");
        } else {
            $this->datagrid->setActionColumnVisible(false);
        }
        $this->datagrid->setColumns("No.", "Nomor PO", "Tanggal", "To", "Subject", "No RF", "Submitter");
        $this->datagrid->setPaginationDataNew($this->model_transaksi_internal->get_scalar("SELECT COUNT(*) as jml FROM data_po_to_supplier q $where", "jml"), $length, "transaksi_internal/po_to_supplier", $rowCount, $offset);
        $this->datagrid->setButtonExportVisible(false);
        if ($rowCount > 0) {
            $nomor = $offset + 1;

            foreach ($result->result() as $row) {
                $rowID = $row->id_po;
                if (!$is_popup) {
                    $this->datagrid->addRowAction("edit('" . $rowID . "')", "edit", "Ubah PO");
                    $this->datagrid->addRowAction("hapus('" . $rowID . "')", "delete", "Hapus PO");
                    $this->datagrid->addRowAction("cetak('" . $rowID . "')", "resume", "Cetak QN");                    
                } else {
                    $this->datagrid->onRowClickAction("parent.parent._obj_fSendValue('" . $rowID . "')");
                }

                $this->datagrid->addRowData(
                        $nomor++, $row->nomor_po, $row->tanggal_po, $row->nama_supplier, $row->subject, $row->rf_number, $row->submitter
                );
            }
        } else {
            $this->datagrid->setEmptyDataState("Tidak ada data");
        }

        $data['date_picker'] = new jDatePicker();
        $data['filter_panel'] = $filter_panel;

        if (!$is_popup) {
            $data['breadcrumb'] = $this->breadCrumb(true);
            $this->loadMenu('transaksi_internal/po_to_supplier', $data);
        }
        else
            $this->loadMenuHeaderPopup('transaksi_internal/po_to_supplier', $data);
    }

    public function po_to_supplier_add($kode) {
        $data = array();

        if ($this->input->post("btnSubmit")) {
            $vars = array(
                "nama_supplier" => "",
                "id_supplier" => "",
                "tanggal_po" => date("Y-m-d"),
                "alamat_detail_supplier" => "",
                "nomor_po" => "",
                "rf_number" => "",
                "alamat_komplit" => "",
                "kontak_komplit" => "",
                "attendance" => "",
                "id_port" => "",
                "id_vessel" => "",
                "subject" => "",
                "crc" => "IDR",
                "ppn" => 0,
                "pic_perusahaan" => "",
                "urgensi" => "",
                "diskon" => 0,
                "termcondition" => 1,
                "approved_by" => "",
                "quote_by" => $this->userauth->getNickName(),
                "btnSubmit" => "Save",
                "id_item" => array(),
                "nama_item" => array(),
                "quantity" => array(),
                "harga_beli" => array(),
                "harga_jual" => array(),
                "harga_beli_dollar" => array(),
                "harga_jual_dollar" => array(),
                "satuan" => array()
            );
            $data = array();
            retrieve_request($data, $vars);
            $data["submitter"] = $this->userauth->getNik();
            $data["date_submit"] = date("Y-m-d H:i:s");
            $data["using_dollar_currency"] = $data["crc"] == "USD" ? 1 : 0;

            if ($kode == "") {
                if (empty($data["id_supplier"]))
                    $data["id_supplier"] = $this->model_transaksi_internal->insertSupplier($data);
                $id_po = $this->model_transaksi_internal->insertPOSupp($data);
            } else {
                $id_po = $kode;
                $this->model_transaksi_internal->updatePOSupp($data, $id_po);
            }

            $this->model_transaksi_internal->db->delete("data_po_to_supplier_item", "id_po = '$id_po'");
            $i = 0;
            foreach ($data["id_item"] as $key => $id) {
                $varData = array(
                    "id_po" => $id_po,
                    "id_item" => $key,
                    "nama_item" => $data["nama_item"][$i],
                    "satuan_beli" => $data["satuan"][$i],
                    "quantity" => $data["quantity"][$i],
                    "harga_beli" => $data["harga_beli"][$i],
                    "harga_jual" => $data["harga_jual"][$i],
                    "harga_beli_dollar" => $data["harga_beli_dollar"][$i],
                    "harga_jual_dollar" => $data["harga_jual_dollar"][$i]
                );
                $this->model_transaksi_internal->insertPOSuppItem($varData);
                $i++;
            }

            $data["is_success"] = 1;
            $data["kode"] = $id_po;

            if (!$data["is_success"] && count($data["id_item"]) > 0) {
                $this->load->library("dbresult_dummy");

                foreach ($data["id_item"] as $key => $id) {
                    $item = $this->model_transaksi_internal->getItem($id);
                    $this->dbresult_dummy->new_object($item);
                    $this->dbresult_dummy->assoc("quantity", $data["quantity"][$key]);
                    $this->dbresult_dummy->insert_object();
                }

                $data["item"] = $this->dbresult_dummy;
            }
        }

        if ($kode != "") {
            retrieve_po_data($data, $kode);
            $data["kode"] = $kode;
        } else {
            $data["tanggal_po"] = date("Y-m-d");
            $data["quote_by"] = $this->userauth->getNickName();
            $data["diskon"] = 0;
        }

        $query = $this->model_transaksi_internal->getSupplierList();
        $queryTC = $this->model_transaksi_internal->getTermConditionList();
        $prefix = $this->model_transaksi_internal->getPrefixPOSuppNo();
        $data["supplierlist"] = $query->result();
        $data["termconditionlist"] = $queryTC->result();
        $data["prefix"] = $prefix;

        $data['gbsupp'] = $this->greybox->createLink(base_url() . 'index.php/popup/supplier', '<span></span>', 'Cari Supplier', 'find', '', 750, 450);
        $data['gbitem'] = $this->greybox->createLink(base_url() . 'index.php/popup/item_finalisasi_dollar', '<span>Tambah Item</span>', 'Tambah Item', 'find', '', 1024, 450);
        $data['gbvessel'] = $this->greybox->createLink(base_url() . 'index.php/popup/vessel', '<span></span>', 'Cari Vessel', 'find', '', 500, 450);
        $data['gbport'] = $this->greybox->createLink(base_url() . 'index.php/popup/port', '<span></span>', 'Cari Port', 'find', '', 750, 450);

        $this->loadMenuHeaderPopup("transaksi_internal/po_to_supplier_add", $data);
    }

    public function po_to_supplier_delete($kode) {
        $this->model_transaksi_internal->deletePOSupp($kode);
        echo "<script>alert('Data berhasil dihapus');</script>";
        echo "<script>location.href = '" . site_url("transaksi_internal/po_to_supplier?" . $_SERVER["QUERY_STRING"]) . "'</script>";
    }

    public function po_to_supplier_print($kode = "") {
        $data = array();
        retrieve_po_data($data, $kode);

        $this->load->library("dcpdf");

        $obj_pdf = new dcpdf('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $obj_pdf->SetCreator(PDF_CREATOR);
        $title = "Penawaran Biaya Keagenan";
        $obj_pdf->SetTitle($title);
        if ($data["use_header"]) {
            $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
            $obj_pdf->setFooterVisible(TRUE);
        }
        $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        $obj_pdf->SetDefaultMonospacedFont('helvetica');
        $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $obj_pdf->SetFont('times', '', 10);
        $obj_pdf->setFontSubsetting(false);
        $obj_pdf->AddPage();
        $content = $this->load->view("transaksi_internal/po_to_supplier_print", $data, true);
        $obj_pdf->writeHTML($content, true, false, true, false, '');
        $obj_pdf->Output('po_ke_supplier-' . $kode . '.pdf', 'I');
    }

    public function po_to_supplier_print_penunjukan($kode = "") {
        $data = array();
        retrieve_po_data($data, $kode);

        $this->load->library("dcpdf");

        $obj_pdf = new dcpdf('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $obj_pdf->SetCreator(PDF_CREATOR);
        $title = "Surat Penunjukan";
        $obj_pdf->SetTitle($title);
        if ($data["use_header"]) {
            $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
            $obj_pdf->setFooterVisible(TRUE);
        }
        $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        $obj_pdf->SetDefaultMonospacedFont('helvetica');
        $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $obj_pdf->SetFont('times', '', 10);
        $obj_pdf->setFontSubsetting(false);
        $obj_pdf->AddPage();
        $content = $this->load->view("transaksi_internal/po_to_supplier_print_penunjukan", $data, true);
        $obj_pdf->writeHTML($content, true, false, true, false, '');
        $obj_pdf->Output('po_ke_supplier-' . $kode . '.pdf', 'I');
    }

    public function po_to_supplier_export() {
        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-d");
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
        $data['srcPeriodMode'] = $this->input->get_post('srcPeriodMode') != "";

        $field_name = array("q.nomor_po", "q.subject", "c.nama_supplier");
        $field_title = array("Nomor PO", "Subjek", "To");
        $field_type = array("text", "text", "text");

        $filter_panel = new FilterPanel(base_url() . "transaksi/po_to_supplier", $field_name, $field_title, $field_type);
        if ($data['srcPeriodMode'] == 'include')
            $where = " WHERE date(q.tanggal_po) BETWEEN '" . $data['srcPeriodStart'] . "' AND '" . $data['srcPeriodEnd'] . "' ";
        else
            $where = " WHERE TRUE ";
        $filter = $filter_panel->getFilterString();
        $where .= $filter ? " AND $filter " : "";

        $queryExport = "SELECT q.nomor_po, q.tanggal_po, q.rf_number, q.using_dollar_currency, q.using_ppn, q.approved_by, q.quote_by,
                q.submitter, q.date_submit, q.subject, c.nama_supplier, c.kota_supplier, c.alamat_supplier, c.alamat_detail_supplier, c.kode_pos_supplier,
                c.telepon_supplier, c.fax_supplier, c.email_supplier, c.attendance
                FROM data_po_to_supplier q
                LEFT JOIN master_supplier c ON q.id_supplier = c.id_supplier
                LEFT JOIN master_term_condition t ON t.id_tc = q.id_tc
                $where";

        $this->export($queryExport);
    }

    /**
     * INVOICE
     */
    public function invoice_from_supplier($jenis_invoice = "") {
        $this->load->library("datagrid");

        $data = array();

        $this->log_event = "Membuka menu invoice dari supplier";

        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-d");
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
        $data['srcPeriodMode'] = $this->input->get_post('srcPeriodMode') != "";

        $field_name = array("p.nomor_invoice", "p.subject", "c.nama_supplier", "p.list_po_id");
        $field_title = array("No. Invoice", "Subjek", "Supplier", "No. PO");
        $field_type = array("text", "text", "text", "text");

        $filter_panel = new FilterPanel(base_url() . "transaksi)internal/invoice", $field_name, $field_title, $field_type);
        if ($data['srcPeriodMode'] == 'include')
            $where = " WHERE date(p.tanggal_invoice) BETWEEN '" . $data['srcPeriodStart'] . "' AND '" . $data['srcPeriodEnd'] . "' ";
        else
            $where = " WHERE TRUE ";
        $filter = $filter_panel->getFilterString();
        $where .= $filter ? " AND $filter " : "";

        if ($jenis_invoice != "") {
            $where .= " and p.is_final = " . $jenis_invoice;
        }

        $offset = $this->input->get("per_page") ? $this->input->get("per_page") : 0;
        $length = 30;
        $result = $this->model_transaksi_internal->getInvoiceSuppData($where, $offset, $length);

        $rowCount = $result->num_rows();

        $this->datagrid->setActionColumnsWidth(50);
        $this->datagrid->addMenu("<a href=\"" . base_url() . "index.php/transaksi_internal/invoice_from_supplier/1?" . $this->input->server("QUERY_STRING") . "\">Lunas</a>/");
        $this->datagrid->addMenu("<a href=\"" . base_url() . "index.php/transaksi_internal/invoice_from_supplier/0?" . $this->input->server("QUERY_STRING") . "\">Belum Lunas</a>/");
        $this->datagrid->addMenu("<a href=\"" . base_url() . "index.php/transaksi_internal/invoice_from_supplier/?" . $this->input->server("QUERY_STRING") . "\">Semua</a>");
        $this->datagrid->addMenu(GreyBox::createLink(base_url() . "index.php/transaksi_internal/invoice_from_supplier_add/", "", "Tambah Data", "add", "onclick", 1024, 600));
        $this->datagrid->addMenu("<a href=\"" . base_url() . "index.php/transaksi_internal/invoice_from_supplier_export/$jenis_invoice?" . $this->input->server("QUERY_STRING") . "\" class=\"report\" title=\"Export Data Invoice Dari Supplier\">&nbsp;</a>");
        $this->datagrid->setColumns("No.", "Nomor Invoice", "Tanggal", "To", "Daftar PO", "Catatan", "Submitter");
        $this->datagrid->setPaginationDataNew($this->model_transaksi_internal->get_scalar("SELECT COUNT(*) as jml FROM data_invoice_from_supplier p $where", "jml"), $length, "transaksi_internal/invoice_from_supplier", $rowCount, $offset);
        $this->datagrid->setButtonExportVisible(false);

        if ($rowCount > 0) {
            $nomor = $offset + 1;

            foreach ($result->result() as $row) {
                $rowID = $row->id_invoice;
                if ($row->list_po_id != "")
                    $list_po = $this->model_transaksi_internal->get_scalar("SELECT GROUP_CONCAT(nomor_po SEPARATOR ',') as ids FROM data_po_to_supplier WHERE id_po IN ($row->list_po_id)", "ids");
                else
                    $list_po = "-";

                if (!$is_popup) {
                    $this->datagrid->addRowAction("edit('" . $rowID . "')", "edit", "Ubah Purchase");
                    $this->datagrid->addRowAction("hapus('" . $rowID . "')", "delete", "Hapus Purchase");
                    if ($row->is_final == 0) {
                        $this->datagrid->addRowAction("finalisasi('" . $rowID . "','invoice_supp')", "snapshot", "Finalisasi Invoice");
                        $this->datagrid->setRowStyle("GridItem2");
                    } else {
                        $this->datagrid->setRowStyle("GridItem1");
                    }
                } else {
                    $this->datagrid->onRowClickAction("parent.parent._obj_fSendValue('" . $rowID . "')");
                }

                $this->datagrid->addRowData(
                        $nomor++, $row->nomor_invoice, $row->tanggal_invoice, $row->nama_supplier, str_replace(",", "<br/>", $list_po), $row->catatan_invoice, $row->submitter
                );
            }
        } else {
            $this->datagrid->setEmptyDataState("Tidak ada data");
        }

        $data['date_picker'] = new jDatePicker();
        $data['filter_panel'] = $filter_panel;

        $data['breadcrumb'] = $this->breadCrumb(true);
        $this->loadMenu('transaksi_internal/invoice_from_supplier', $data);
    }

    public function invoice_from_supplier_add($kode = "") {
        $data = array();

        if ($this->input->post("btnSubmit")) {
            $vars = array(
                "tanggal_invoice" => date("Y-m-d"),
                "list_po_id" => "",
                "catatan_invoice" => "",
                "id_customer" => "",
                "id_item" => array(),
                "nama_item" => array(),
                "quantity" => array(),
                "harga_beli" => array(),
                "harga_jual" => array(),
                "harga_beli_dollar" => array(),
                "harga_jual_dollar" => array(),
                "satuan" => array(),
                "selected" => array(),
                "crc" => "IDR",
                "btnSubmit" => "Save",
                "nama_supplier" => "",
                "alamat_detail_supplier" => "",
                "alamat_komplit" => "",
                "kontak_komplit" => "",
                "nomor_invoice" => "",
                "diskon" => 0
            );

            $data = array();
            retrieve_request($data, $vars);

            $data["submitter"] = $this->userauth->getNik();
            $data["date_submit"] = date("Y-m-d H:i:s");
            $data["using_dollar_currency"] = $data["crc"] == "USD" ? 1 : 0;

            if ($data["nama_supplier"] == "" && $data["list_po_id"] == "")
                $data["error"] = "If list quotation ID is empty then Customer name can't be empty";
            else if (count($data["selected"]) <= 0)
                $data["error"] = "Item can't be empty";
            else {

                $upload_success = true;
                if ($_FILES["file_upload"]["name"] != "") {
                    $config = array();

                    $dir = str_replace("system/", "", BASEPATH) . 'import/';

                    if (!is_dir($dir)) {
                        mkdir($dir, 777);
                    }

                    $config['upload_path'] = $dir;
                    $config['overwrite'] = true;
                    $config["allowed_types"] = "doc|docx|xls|xlsx|pdf|txt|rtf|csv|jpg|jpeg|bmp|png";
                    $config["file_name"] = "invoice_from_supp_" . date("dmYHis");

                    $this->load->library('upload', $config);

                    if (!$this->upload->do_upload("file_upload")) {
                        $data["error"] = $this->upload->display_errors();
                        $upload_success = false;
                    } else {
                        $data["upload_data"] = $this->upload->data();
                        $data["file_upload"] = $data["upload_data"]["file_name"];
                    }
                }

                if ($upload_success) {
                    if (empty($data["id_supplier"]))
                        $data["id_supplier"] = $this->model_transaksi_internal->insertSupplier($data);
                    if ($kode == "")
                        $id_invoice = $this->model_transaksi_internal->insertInvoiceSupp($data);
                    else {
                        $id_invoice = $kode;
                        $this->model_transaksi_internal->updateInvoiceSupp($data, $id_invoice);
                    }

                    $this->model_transaksi_internal->db->delete("data_invoice_from_supplier_item", "id_invoice = '$id_invoice'");
                    foreach ($data["id_item"] as $key => $id) {
                        if (in_array($id, $data["selected"])) {
                            $this->model_transaksi_internal->insertInvoiceSuppItem($id_invoice, $id, $data["quantity"][$key]);
                        }
                    }
                    $data["is_success"] = 1;
                    $data["kode"] = $id_invoice;
                }
            }
            if (!$data["is_success"] && count($data["id_item"]) > 0) {
                $this->load->library("dbresult_dummy");

                foreach ($data["id_item"] as $key => $id) {
                    $item = $this->model_transaksi_internal->getItem($id);
                    $this->dbresult_dummy->new_object($item);
                    $this->dbresult_dummy->assoc("quantity", $data["quantity"][$key]);
                    $this->dbresult_dummy->insert_object();
                }

                $data["item"] = $this->dbresult_dummy;
            }
        }

        if ($kode != "") {
            retrieve_invoice_data($data, $kode);
            $data["kode"] = $kode;
        } else {
            $data["tanggal_invoice"] = date("Y-m-d");
            $data["diskon"] = 0;
        }

        $data['gbquote'] = $this->greybox->createLink(base_url() . 'index.php/popup/polist', '<span></span>', 'Cari Data PO', 'find', '', 500, 450);
        $data['gbitem'] = $this->greybox->createLink(base_url() . 'index.php/popup/master_item', '<span>Tambah Item</span>', 'Tambah Item', 'find', '', 820, 450);

        $this->loadMenuHeaderPopup("transaksi_internal/invoice_from_supplier_add", $data);
    }

    public function invoice_from_supplier_delete($kode) {
        $this->model_transaksi_internal->deleteInvoiceSupp($kode);
        echo "<script>alert('Data berhasil dihapus');</script>";
        echo "<script>location.href = '" . site_url("transaksi_internal/invoice_from_supplier?" . $_SERVER["QUERY_STRING"]) . "'</script>";
    }

    public function invoice_from_supplier_export($jenis_invoice = "") {
        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-d");
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
        $data['srcPeriodMode'] = $this->input->get_post('srcPeriodMode') != "";

        $field_name = array("p.nomor_invoice", "p.subject", "c.nama_supplier", "p.list_po_id");
        $field_title = array("No. Invoice", "Subjek", "Supplier", "No. PO");
        $field_type = array("text", "text", "text", "text");

        $filter_panel = new FilterPanel(base_url() . "transaksi)internal/invoice", $field_name, $field_title, $field_type);
        if ($data['srcPeriodMode'] == 'include')
            $where = " WHERE date(p.tanggal_invoice) BETWEEN '" . $data['srcPeriodStart'] . "' AND '" . $data['srcPeriodEnd'] . "' ";
        else
            $where = " WHERE TRUE ";

        if ($jenis_invoice != "") {
            $where .= " and p.is_final = " . $jenis_invoice;
        }

        $filter = $filter_panel->getFilterString();
        $where .= $filter ? " AND $filter " : "";

        $queryExport = "SELECT p.*, c.*
                FROM data_invoice_from_supplier p
                LEFT JOIN master_supplier c ON p.id_supplier = c.id_supplier
                $where";

        $this->export($queryExport);
    }

}

?>
